package com.sun.servlet;

import com.sun.util.Constant;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Sun
 * @Date 2020/4/23 20:29
 * @Version 1.0
 */
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //获得登陆页面输入的用户名参数
        String username = req.getParameter(Constant.USER_SESSION);

        if(username.equals("admin")){
            req.getSession().setAttribute(Constant.USER_SESSION, req.getSession().getId());
            resp.sendRedirect("/sys/success.jsp");//登陆成功就重定向进入成功页面
        }else{
            resp.sendRedirect("/sys/error.jsp");//否则进入失败页面
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
